package h0901;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
  * @description 子集
  * @author 不知名帅哥
  * @date 2024/9/1 0:15
  * @version 1.0
*/
public class Subset {
    public static void main(String[] args) {

    }
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res=new ArrayList<>();
        LinkedList<Integer> temp=new LinkedList<>();
        backTrack(nums,res,temp,0);
        return res;
    }

    private void backTrack(int[] nums, List<List<Integer>> res, LinkedList<Integer> temp, int start) {
        res.add(new LinkedList<>(temp));
        for (int j = start; j < nums.length; j++) {
            temp.addLast(nums[j]);
            backTrack(nums, res, temp, j+1);
            temp.removeLast();
        }
    }
}
